<template>
    <el-dialog v-model="props.modGenerator" title="生成代码" @close="close" style="width: 30%">
        <el-form ref="dataForm" :rules="rules" :model="form" label-width="100px" align="center">
            <el-form-item label="模块名称" prop="moduleName">
                <el-input v-model="form.moduleName"/>
            </el-form-item>
            <el-form-item label="覆盖生成" prop="fileOverride">
                <el-switch v-model="form.fileOverride"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="doGenerator">确定</el-button>
                <el-button @click="close" type="primary" >取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script setup>
    import {ref,reactive,onUpdated} from 'vue'
    import request from '@/utils/request.js'
    import { ElMessage } from 'element-plus'
    const  emits = defineEmits(['close','saveModuleName'])

    let dataForm = ref(null)
    let props = defineProps(['modGenerator','tableName','id'])
    let form = reactive({})
    const rules = reactive({
        moduleName: [{required: true,message: '请输入模块名称', trigger: 'blur'},],
    })
    onUpdated(function () {

    })

    function close(){
        emits("close")
        dataForm.value.resetFields()//重置表单校验
    }

    function doGenerator(){
        dataForm.value.validate((valid, fields)=> {
            form.tableName = props.tableName
            request.post('/api/generator/doGenerator', form).then(resp => {
                close()
                ElMessage({message: `${props.tableName}生成完成！`,type: 'success'})
            });
        })
    }

</script>

<style scoped>

</style>